package com.my.helper.activity;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.WindowManager;

import com.my.helper.MainActivity;
import com.my.helper.R;
import com.my.helper.util.CacheActivity;
import com.my.helper.util.SharedPrefUtil;

public class SplashActivity extends AppCompatActivity {
    private SharedPrefUtil sp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        } else {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON

            );
        }

        CacheActivity.addActivity(this);

        sp = new SharedPrefUtil(this, "myHelper");

        /**
         * 3秒后发送消息提示跳转界面
         */
        myHandler.sendEmptyMessageDelayed(100, 3000);
    }

    public Handler myHandler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            switch (msg.what) {
                case 100:

                    if (sp.getString("user_id","").equals("")){
                        Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
                        startActivity(intent);
                        CacheActivity.finishSingleActivityByClass(SplashActivity.class);
                        myHandler.removeCallbacksAndMessages(null);
                    }else {
                        Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                        startActivity(intent);
                        CacheActivity.finishSingleActivityByClass(SplashActivity.class);
                        myHandler.removeCallbacksAndMessages(null);
                    }
                    break;
            }
        }
    };
}
